#define CLR_NULL		D3DCOLOR_ARGB(0,0,0,0);
#define CLR_WHITE		D3DCOLOR_ARGB(255, 255, 255, 255)
#define CLR_GREY		D3DCOLOR_ARGB(255, 128, 128, 128)
#define CLR_BLACK		D3DCOLOR_ARGB(255, 0, 0, 0)
#define CLR_RED			D3DCOLOR_ARGB(255, 255, 0, 0)
#define CLR_GREEN		D3DCOLOR_ARGB(255, 0, 255, 0)
#define CLR_BLUE		D3DCOLOR_ARGB(255, 0, 0, 255)
#define CLR_LIGHTBLUE	D3DCOLOR_ARGB(255, 0, 255, 255)
#define CLR_MAJENTA		D3DCOLOR_ARGB(255, 255, 0, 255)
#define CLR_YELLOW		D3DCOLOR_ARGB(255, 255, 255, 0)

#include <d3d9.h>
#include <d3dx9.h>

#include "CSprite.h"
#include "DXUT.h"
#include "SDKmisc.h"


class CGraphicsHandler{
private:
	ID3DXSprite*        pSprite;		// Sprite for draw sprite calls
	ID3DXFont*          pFont;         // Font for drawing text
	ID3DXSprite*        pTextSprite;   // Sprite for batching draw text calls
	CDXUTTextHelper*	txtHelper;

	D3DXVECTOR2			vScale;
	D3DCOLOR			Color;
	float				fAngle;
	int					nFrame;

	D3DXMATRIX mScale;
	D3DXMATRIX mRotation;
	D3DXMATRIX mTranslation;
	D3DXMATRIX mResize;
public:

	CGraphicsHandler();
	~CGraphicsHandler();

	void Init(IDirect3DDevice9* pd3dDevice);
	void Reset(IDirect3DDevice9* pd3dDevice);
	void Lost();
	void Release();

	void BeginRender();
	void EndRender();

	//Setters
	void SetScale(D3DXVECTOR2 scale){ vScale = scale; D3DXMatrixScaling(&mScale, vScale.x,vScale.y,1.0f);};
	void SetAngle(float angle)		{ fAngle = angle*-1; D3DXMatrixRotationZ(&mRotation, fAngle);};
	void SetColor(D3DCOLOR color)	{ Color = color; };
	void SetFrame(int frame)		{ nFrame = frame+1; };

	//Getters
	D3DXVECTOR2 GetScale(){return vScale;};
	D3DCOLOR	GetColor(){return Color;};
	float		GetAngle(){return fAngle;};
	int			GetFrame(){return nFrame;};

	//2D Drawing Functions
	//Normal Functions draw sprites from centre, and will follow the camera/view
	//TL Functions draw sprites from top left, and will not follow the camera/view
	//void DrawTileset(CSprite *sprite, int xframe, int yframe, D3DXVECTOR2 pos);
	void DrawSprite(CSprite *sprite, D3DXVECTOR2 pos);

	void DrawText(const WCHAR* txt, D3DXVECTOR2 pos);
};
